﻿using FieldTools.Client.Entity.MyQQ;
using FieldTools.Client.Model.Base;
using System.Collections.Generic;
using System.Collections.ObjectModel;

namespace FieldTools.Client.Model.Window
{
    /// <summary>
    /// MyQQ框架对接数据模型
    /// </summary>
    [Save]
    public class MyQQModel : BaseModel 
    {
        /// <summary>
        /// 
        /// </summary>
        public MyQQModel() : base(System.Reflection.MethodBase.GetCurrentMethod()?.DeclaringType.Name)
        {
            //很怪，这里这俩初始化，每调用一次都会导致全局对象变长……
            //if (robotMasters == null || (robotMasters != null && robotMasters.RobotMasterItems.Count == 0))
                //robotMasters = new(new List<RobotMaster>() { new() { Id = "456789", RobotQQ = "123456", MasterQQ = "123465", IsOn = true } });
            //if ((custonOrders != null && custonOrders.OrderDataItems.Count==0))
                //custonOrders = new(new List<OrderData>() { new() { Id = "132456", Keyword = "#FieldTools", Reply = "自定义指令识别成功", IsOn = true, IsAt = false, IsPrivate = true, Remarks = "这是空配置情况下的默认回复指令" } });
            posturl = "http://localhost:5556/";
            token = "666";
            isSaveQQInfo = false;
        }

        private RobotConnectConfig? onebotConfig;
        /// <summary>
        /// OnebotConfig
        /// </summary>
        public RobotConnectConfig? OnebotConfig
        {
            get => onebotConfig;
            set
            {
                onebotConfig = value;
                //对象无法直接通知，使用按钮操作
                SavaConfigAndRaisePropertyChanged(this, nameof(OnebotConfig), value);
            }
        }

        private string? posturl;
        /// <summary>
        /// Posturl
        /// </summary>
        public string? Posturl 
        { 
            get => posturl; 
            set {
                posturl = value;
                SavaConfigAndRaisePropertyChanged(this, nameof(Posturl), value);
            }
        }

        private string? token;
        /// <summary>
        /// Token
        /// </summary>
        public string? Token 
        { 
            get => token; 
            set {
                token = value;
                SavaConfigAndRaisePropertyChanged(this, nameof(Token), value);
            }
        }

        private ObservableCollection<RobotTask>? robotTasks;
        /// <summary>
        /// 自动请求任务
        /// </summary>
        public ObservableCollection<RobotTask>? RobotTasks
        {
            get => robotTasks;
            set
            {
                robotTasks = value;
                SavaConfigAndRaisePropertyChanged(this, nameof(RobotTasks), value);
            }
        }

        private ObservableCollection<RobotMaster>? robotMasters;
        /// <summary>
        /// 机器人管理员关联
        /// </summary>
        public ObservableCollection<RobotMaster>? RobotMasters { 
            get => robotMasters;
            set {  
                robotMasters = value;
                SavaConfigAndRaisePropertyChanged(this, nameof(RobotMasters), value);
            }
        }

        private ObservableCollection<OrderData>? custonOrders;
        /// <summary>
        /// 自定义回复指令
        /// </summary>
        public ObservableCollection<OrderData>? CustonOrders
        {
            get => custonOrders;
            set
            {
                custonOrders = value;
                SavaConfigAndRaisePropertyChanged(this, nameof(CustonOrders), value);
            }
        }

        /// <summary>
        /// 预定义回复指令
        /// </summary>
        public static PredefineContents? PredefineContents => new();

        private string? jsFilePath;
        /// <summary>
        /// JS文件路径
        /// </summary>
        public string? JsFilePath
        {
            get => jsFilePath;
            set
            {
                jsFilePath = value;
                SavaConfigAndRaisePropertyChanged(this, nameof(JsFilePath), value);
            }
        }

        private bool isHandleJS = false;
        /// <summary>
        /// 是否启用js脚本
        /// </summary>
        public bool IsHandleJS
        {
            get => isHandleJS;
            set
            {
                isHandleJS = value;
                SavaConfigAndRaisePropertyChanged(this, nameof(IsHandleJS), value);
            }
        }

        private bool onlineGetInfoTagForMyQQ = false;
        /// <summary>
        /// 从线上获取MyQQ相关配置
        /// </summary>
        public bool OnlineGetInfoTagForMyQQ
        {
            get => onlineGetInfoTagForMyQQ;
            set
            {
                onlineGetInfoTagForMyQQ = value;
                SavaConfigAndRaisePropertyChanged(this, nameof(OnlineGetInfoTagForMyQQ), value);
            }
        }

        private bool isSaveQQInfo = false;
        /// <summary>
        /// 是否保存收到的QQ消息
        /// </summary>
        public bool IsSaveQQInfo
        {
            get => isSaveQQInfo;
            set
            {
                isSaveQQInfo = value;
                SavaConfigAndRaisePropertyChanged(this, nameof(IsSaveQQInfo), value);
            }
        }

        private string? jsFilePathForMyQQ;
        /// <summary>
        /// js文件路径
        /// </summary>
        public string? JsFilePathForMyQQ
        {
            get => jsFilePathForMyQQ;
            set
            {
                jsFilePathForMyQQ = value;
                SavaConfigAndRaisePropertyChanged(this, nameof(JsFilePathForMyQQ), value);
            }
        }

        private bool? isHandleJSForMyQQ;
        /// <summary>
        /// 是否启用js脚本进行数据处理
        /// </summary>
        public bool? IsHandleJSForMyQQ
        {
            get => isHandleJSForMyQQ;
            set
            {
                isHandleJSForMyQQ = value;
                SavaConfigAndRaisePropertyChanged(this, nameof(IsHandleJSForMyQQ), value);
            }
        }
    }
}
